<?php
/**
 * Created by PhpStorm.
 * User: mr.lee
 * Date: 2018/10/17
 * Time: 3:00 PM
 */

namespace app\index\controller;


use app\common\controller\Pub;
use Bank\HuifuServer;
use think\Controller;

class Huifu extends Controller
{


    public function uploadimg()
    {
//      01:营业执照图片
//02:税务登记证
//03:组织机构代码证
//04:开户许可证
//05:法人身份证正面
//06:法人身份证反面
//07:结算人身份证正面
//08:结算人身份证反面
//09:商务协议
//10:公司照片一
//11:公司照片二
//12:公司照片三
//13:联系人身份证正面
//14:联系人身份证反面
        $url = "https://payos-1251056009.cos.ap-shanghai.myqcloud.com/uploads/machtobank/1540553942000%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181002030047.jpg";
        $img=$this->download_image($url, $fileName = '01', "down");
        $data['picture'] = "@".$img['saveDir']."/".$img['fileName'];
//        var_dump($data['picture']);
//        exit();
        $JsonData['agentId'] = "310000015000064160";
        $JsonData['memberId'] = "";
        $JsonData['photoType'] = "01";
        $JsonData['reqSerialNum'] = "test";
        $HuifuServer = new HuifuServer();
        $salt = "chinapnr";
        $ss2 = hash("sha256", json_encode($JsonData, JSON_UNESCAPED_UNICODE) . $salt);
        $data['checkValue'] = $ss2;
        $data['jsonData'] = json_encode($JsonData, JSON_UNESCAPED_UNICODE);
        $res = $HuifuServer->upload_img($data);
        if ($res['respCode'] == "0000") {
            $re_param['result_code'] = "SUCCESS";
            $re_param['result_msg'] = $res['respDesc'];
            $re_param['info'] = $res['jsonData'];
            $infos=json_decode($res['jsonData'],true);
            $re_param['imgurl'] = $infos['pictureID'];
        } else {
            $re_param['result_code'] = "FAIL";
            $re_param['result_msg'] = $res['respDesc'];
        }
        return $re_param;
    }

    public function mch_join()
    {

        $JsonData['merchClass'] = "1";
        $JsonData['merchType'] = "2";
        $JsonData['merchName'] = "河南悟能网络科技有限公司";
        $JsonData['merchShortName'] = "河南悟能网络科技有限公司";
        $JsonData['userDefinedName'] = $JsonData['merchShortName'];
        $JsonData['regProvId'] = "河南";
        $JsonData['regCityId'] = "安阳市";
        $JsonData['regAreaId'] = "林州市";
        $JsonData['regAddr'] = "红旗渠大道国家863林州科技产业园1号楼";
        $JsonData['provId'] = "河南";
        $JsonData['cityId'] = "安阳市";
        $JsonData['areaId'] = "林州市";
        $JsonData['merchAddr'] = "红旗渠大道国家863林州科技产业园1号楼";
        $JsonData['businessShours'] = "09:00";
        $JsonData['businessEhours'] = "23:00";
        $JsonData['isCreditCode'] = "1";
        $JsonData['creditCode'] = "914105810969390037";
        $JsonData['licType'] = "1";
        $JsonData['licSdate'] = "20140409";
        $JsonData['licEdate'] = "20440408";
        $JsonData['cateType'] = "1";
        $JsonData['legalName'] = "李国梁";
        $JsonData['idType'] = "01";
        $JsonData['idNo'] = "410521199303180077";
        $JsonData['idValidType'] = "1";
        $JsonData['idSdate'] = "20100701";
        $JsonData['idEdate'] = "20200701";
        $JsonData['contactName'] = "李国梁";
        $JsonData['contactIdType'] = "01";
        $JsonData['contactIdNo'] = "410521199303180077";
        $JsonData['contactIdValidType'] = "1";
        $JsonData['contactIdSdate'] = "20100701";
        $JsonData['contactIdEdate'] = "20200701";
        $JsonData['contactTelno'] = "18568816812";
        $JsonData['contactEmail'] = "lsz@weilinzhou.com";
        $JsonData['contractNum'] = "wn-" . date('Ymd') . rand(100, 300);
        $JsonData['signName'] = "李世正";
        $JsonData['signDate'] = "20181018";
        $JsonData['signSdate'] = "20181018";
        $JsonData['signEdate'] = "20201018";
        $JsonData['tellerId'] = "18568816812";
        $JsonData['isSendMes'] = "1";
        $JsonData['isPrivate'] = "0";
        $JsonData['bankActName'] = "河南悟能网络科技有限公司";
        $JsonData['bankActId'] = "1706922009100000516";
        $JsonData['bankProvId'] = "河南";
        $JsonData['bankCityId'] = "安阳市";
        $JsonData['bankAreaId'] = "林州市";
        $JsonData['bankName'] = "中国工商银行";
        $JsonData['settleTerm'] = "2";
        $JsonData['fee01'] = "0.38";
        $JsonData['auth23'] = "0";
        $JsonData['auth24'] = "0";
        //微信配置
        $JsonData['auth18'] = "1";
        $JsonData['wechatCateCode'] = "111";
        $JsonData['fee08'] = "0.3800";
        $JsonData['isMerWechat'] = "0";
        //阿里配置
        $JsonData['auth19'] = "1";

        $JsonData['alipayCateCode'] = "2015063000020189";
        $JsonData['fee12'] = "0.3800";
        $JsonData['bgRetUrl'] = urlencode("https://os.wunengkeji.com/huifunotify.php/");
        $JsonData['reqSerialNum'] = "test" . date('YmdHis');
        $JsonData['pnrpayMerType'] = "3";
        $JsonData['picUploadWay'] = "01";
        $JsonData['memberId'] = "310000015000064160";
        $JsonData['opTellerId'] = "18903725210";
        $JsonData3 = json_encode($JsonData, JSON_UNESCAPED_UNICODE);


        $HuifuServer = new HuifuServer();
        $salt = "chinapnr";
        $ss2 = hash("sha256", $JsonData3 . $salt);
        $data['checkValue'] = $ss2;
        $data['jsonData'] = $JsonData3;
        $res = $HuifuServer->mch_join($data);
        if ($res['respCode'] == "0001") {
            $re_param['result_code'] = "SUCCESS";
            $re_param['result_msg'] = $res['respMsg'];
            $re_param['info'] = $res['jsonData'];
        } else {
            $re_param['result_code'] = "FAIL";
            $re_param['result_msg'] = $res['respMsg'];
        }
        return $re_param;
    }

    public function wx_config()
    {
//traceNo	交易跟踪号	String	可空，用于日志记录的跟踪号
//jsonData	json数据	json
//checkValue	加签密文	String
//参数代码	参数名称	数据类型	参数说明
//reqSerialNum	请求流水号	String(120)	必填，由接入方生成且保证唯一
//bgRetUrl	异步通知地址	String(120)	选填
//agentId	代理商号	String(18)	必填
//memberId	商户号	String(18)	必填
//merchName	商户名称	String(60)	必填
//wechatPubNumAppid	公众号支付Appid	String(60)	选填
//wechatPubNumAuth	公众号支付授权目录	String(60)	选填
//wechatPubNum	关注公众号	String(60)	选填
        $JsonData['reqSerialNum'] = "wx_config-" . date('YmdHis') . rand(1000, 9999);
        $JsonData['bgRetUrl'] = "https://os.wunengkeji.com/huifunotify.php";
        $JsonData['agentId'] = "310000015000064160";
        $JsonData['memberId'] = "310000016000065151";
        $JsonData['merchName'] = "河南悟能网络科技有限公司";
        $JsonData['wechatPubNumAppid'] = "wx26dd3a738e5b357c";
        $JsonData['wechatPubNumAuth'] = "https://os.wunengkeji.com/";
        $JsonData['wechatPubNum'] = "wx26dd3a738e5b357c";
        $JsonData3 = json_encode($JsonData, JSON_UNESCAPED_UNICODE);

        $HuifuServer = new HuifuServer();
        $salt = "chinapnr";
        $data['checkValue'] = hash("sha256", $JsonData3 . $salt);
        $data['jsonData'] = $JsonData3;
        $data['traceNo'] = "wx_config-" . date('YmdHis') . rand(1000, 9999);
        $res = $HuifuServer->wx_config($data);
        var_dump($res);

    }

    public function wx_config_query()
    {
//        参数代码	参数名称	数据类型	参数说明
//traceNo	交易跟踪号	String	可空，用于日志记录的跟踪号
//jsonData	json数据	json
//checkData
//	加签密文	String	salt值加密校验加密算法使用：sha256
//参数代码	参数名称	数据类型	参数说明
//agentId	代理商号	String(18)	必填
//memberId	商户号	String(18)	必填
//merchName	商户名称	String(60)	必填
        $JsonData['agentId'] = "310000015000064160";
        $JsonData['memberId'] = "310000016000065151";
        $JsonData['merchName'] = "河南悟能网络科技有限公司";
        $JsonData3 = json_encode($JsonData, JSON_UNESCAPED_UNICODE);

        $HuifuServer = new HuifuServer();
        $salt = "chinapnr";
        $data['checkValue'] = hash("sha256", $JsonData3 . $salt);
        $data['jsonData'] = $JsonData3;
        $data['traceNo'] = "wx_config_config-" . date('YmdHis') . rand(1000, 9999);
        $res = $HuifuServer->wx_config_query($data);
        var_dump($res);
    }

    //正扫
    public function qrcode_pay()
    {
//        traceNo	请求跟踪号	String	可选，用于交易请求的跟踪号
//jsonData	json数据	String
//checkValue	加签密文	String	必填
//参数代码	参数名称	数据类型	参数说明
//accSplitBunch	分账串	String	可选，4000位，参考4. 分账说明
//termOrdId	终端订单号	String	必填，20-50位，终端侧或者SAAS商户订单号
//appId	微信分配的子商户公众账号ID	String	微信分配的子商户公众账号ID，可选，32位
//devsId	汇付机具号	String	可选 21位（汇付机具必填）
//goodsDesc	商品名称	String	可选，127位，UrlEncode进行编码，如：
//%E6%B5%8B%E8%AF
//memberId	商户号	String	必填，固定18位 汇付分配的商户号
//merOperId	操作员ID	String	必填，最大32位
//ordAmt	订单金额	String	必填，14位，例如： 0.01，单位元
//apiVersion	接口版本号	String	必填:2.0.0.1
//merPriv	扩展域	String	可选, 1500位；商户扩展域、json串格式。
//基站信息：lc(可选，注意若位数不足则用空格补足：MCC（3位）+MNC（2位）+LAC（5位)+CID（5位）)；外部调用标识：callType(可选);
//异步通知地址：merNoticeUrl(可选)；
//基站信息：lc(可选，注意若位数不足则用空格补足：MCC（3位）+MNC（2位）+LAC（5位)+CID（5位）)
//callType:
//01 – 智能POS
//02 – MPOS
//03 – MPOS SDK
//04 – 智能POS SDK
//05 – 传统POS
//06 – 扫码设备
//99 – SAAS通道接入
//payChannelType	支付方式	String	必填，固定2位
//A1 支付宝
//W1 微信
//U1 银联
//outOrdId	外部订单号	String	可选,商户自有系统订单号,最大20位
        $JsonData['termOrdId'] = "H501-" . date('YmdHis') . rand(10000, 99999);
        $JsonData['appId'] = "wx26dd3a738e5b357c";
        $JsonData['goodsDesc'] = "快捷支付";
        $JsonData['memberId'] = "310000016000065151";
        $JsonData['merOperId'] = "18568816812";
        $JsonData['ordAmt'] = "0.01";
        $JsonData['apiVersion'] = "2.0.0.1";
        $JsonData['payChannelType'] = "W1";
        $JsonData['outOrdId'] = "H501-" . date('YmdHi') . rand(10, 99);
        $data['traceNo'] = "pay-" . date('YmdHis') . rand(10000, 99999);
        foreach ($JsonData as $k => $v) {
            $JsonData2[$k] = urlencode($v);
        }
        $JsonData3 = json_encode($JsonData2, JSON_UNESCAPED_UNICODE);
        $HuifuServer = new HuifuServer();
        $data['checkValue'] = $HuifuServer->sign($JsonData3);
        $data['jsonData'] = $JsonData3;
        $data['traceNo'] = "H501-" . date('YmdHis') . rand(1000, 9999);
        $res = $HuifuServer->qrcode_pay($data);
//        $res2=$HuifuServer->get_sign_data(json_decode($res['jsonData']));
        if ($res['respCode'] == "000000") {

            $re_param['result_code'] = "SUCCESS";
            $re_param['result_msg'] = $res['respDesc'];
            $re_param['info'] = $res['jsonData'];
        } else {
            $re_param['result_code'] = "FAIL";
            $re_param['result_msg'] = $res['respDesc'];
        }
        var_dump($re_param);
        return $re_param;

    }

    public function c2b()
    {


    }


}